<template>
  <!--診所信息-->
  <div>
    <el-row>
      <el-col :span="22" :offset="1">
        <el-card shadow="always">
          <el-form :label-position="labelPosition" :inline="true" :model="form">
            <el-form-item style="width: 100%">
              <el-button type="primary" @click="onSubmit" style="float: right">保存</el-button>
            </el-form-item>
            <el-form-item style="width: 30%" align="left" label="诊所编号">
              <el-input v-model="form.id" disabled='disabled'></el-input>
            </el-form-item>
            <el-form-item style="width: 30%" align="left" label="诊所名称">
              <el-input v-model="form.name"></el-input>
            </el-form-item>
            <!------------------------------文件上传--------------------------->
            <el-form-item style="width: 30%" align="left" label="诊所Logo:">
              <el-upload style="float: left"
                         class="avatar-uploader"
                         action="api/clinicinfo/upload"
                         v-if="this.form.url==null"
                         :show-file-list="false"
                         :on-success="handleAvatarSuccess"
                         :before-upload="beforeAvatarUpload">
                <img v-if="imageUrl" :src="imageUrl" class="avatar">
                <i v-else class="el-icon-plus avatar-uploader-icon" style="width: 10px"></i>
              </el-upload>
              <!--图片回显-->
              <el-image
                style="width: 100px; height: 100px;float: left"
                v-show="this.form.logo!=null"
                :src="this.form.logo"
                fit="fill"></el-image>
            </el-form-item>

            <el-form-item style="width: 30%" align="left" label="诊所所有人">
              <el-input v-model="form.owner"></el-input>
            </el-form-item>

            <el-form-item style="width: 30%" align="left" label="诊所所有人电话">
              <el-input v-model="form.phone"></el-input>
            </el-form-item>

            <el-form-item style="width: 30%  " align="left" label="诊所所有人邮箱">
              <el-input v-model="form.email"></el-input>
            </el-form-item>

            <el-form-item style="width: 95%" align="left" label="地址">
              <el-input v-model="form.address"></el-input>
            </el-form-item>

            <el-form-item style="width: 95%" align="left" label="诊所介绍">
              <el-input v-model="form.introduction"></el-input>
            </el-form-item>
          </el-form>
          到期时间：2020-10-23 10:34:56
        </el-card>

      </el-col>
    </el-row>
  </div>
</template>
<script>
  import axios from 'axios';

  export default {
    data() {
      return {
        labelPosition: 'top',
        form: {},
        imageUrl: ''
      };
    },
    methods: {
      handleAvatarSuccess(res, file) {

        this.imageUrl = URL.createObjectURL(file.raw);
        this.form.logo = res;
      },
      beforeAvatarUpload(file) {
        const isJPG = file.type === 'image/jpeg';
        const isLt2M = file.size / 1024 / 1024 < 2;

        if (!isJPG) {
          this.$message.error('上传头像图片只能是 JPG 格式!');
        }
        if (!isLt2M) {
          this.$message.error('上传头像图片大小不能超过 2MB!');
        }
        return isJPG && isLt2M;
      },
      findById: function (id) {
        axios.post("api/clinicinfo/findById", {id: id}).then(res => {
          if (res.data=="noper"){
            alert("你没有权限滚!!!!!!!!")
            this.$router.push("/")
          }
          this.form = res.data;

        })

      },
      onSubmit() {
        console.log(this.form)

        axios.post("api/clinicinfo/saveOrUpdate", this.form).then(res => {
          /* alert(res.data)*/
          if (res.data == "success") {
            this.dialogVisible = false
            this.findAll();
          }
        })
      }
    }
    , mounted() {
      var id = 2468;
      this.findById(id);
    }
  }
</script>
<style>
  .avatar-uploader .el-upload {
    /* border: 1px dashed #d9d9d9;*/
    /*  border-radius: 6px;*/
    cursor: pointer;

    /* overflow: hidden;*/
  }

  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }

  /*  .avatar-uploader-icon {
      font-size: 28px;
      color: #8c939d;
      width: 100px;
      height: 100px;
      line-height: 81px;
      text-align: center;
    }*/

  .avatar {
    width: 1px;
    height: 1px;
    /*display: block;*/
  }

</style>


